package com.morgan.recyclerviewdemo.entity

import android.os.Parcel
import android.os.Parcelable
import androidx.annotation.DrawableRes
import com.github.promeg.pinyinhelper.Pinyin

/**
 *description：
 *<br>author：caowugao
 *<br>time：2020/7/5 0005 10:45
 */
data class TextIconBean(val mText : String, @DrawableRes val mIconResId : Int) : IClassificateTag {
    var mNeedShowHoverTop = true
    override fun needShowHoverTop(): Boolean {
        return mNeedShowHoverTop
    }
    private val mTag : String

    constructor(parcel: Parcel) : this(
        parcel.readString()!!,
        parcel.readInt()
    ) {
        mNeedShowHoverTop = parcel.readByte() != 0.toByte()
    }

    init {
        mTag = Pinyin.toPinyin(mText[0]).toUpperCase().substring(0, 1)
    }

    override fun getTag(): String = mTag
    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(mText)
        parcel.writeInt(mIconResId)
        parcel.writeByte(if (mNeedShowHoverTop) 1 else 0)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<TextIconBean> {
        override fun createFromParcel(parcel: Parcel): TextIconBean {
            return TextIconBean(parcel)
        }

        override fun newArray(size: Int): Array<TextIconBean?> {
            return arrayOfNulls(size)
        }
    }

}